import api from "../../../api";
import {getLtv} from "../../../common/js/util";
export default {
  state:{
    loading:true,
    tableData:null
  },
  getters:{
  },
  mutations:{
    pay_tableData(state,data){
      let s = [1,2,3,4,5,6,7,10,15,20,25,30,45,60];
      state.tableData = data.map((item)=>{
        let len = item.recharge_num.split(",").length;
        s.forEach((val)=>{
          if(val <= len){
            item['LTV'+val] = item.regist_num?(getLtv(item.recharge_num,val)/item.regist_num).toFixed(2):0;
          }
        });
        return item;
      });

    },
    pay_showLoading(state){
      state.loading = true;
    },
    pay_endLoading(state){
      state.loading = false;
    }
  },
  actions:{
    pay_tableData(context,{set,...para}){
      context.commit('pay_showLoading');
      api.getltvList(para,set)
        .then((response) =>{
          context.commit('pay_tableData',response.data);
          context.commit('pay_endLoading');
        })
        .catch((error)=> {
          console.log(error);
        });
    }
  }
}
